package com.dollar.ruyuan_jvm.ygc;

/**
 * jvm （1.8）参数配置
 * -XX:NewSize=5242880 -XX:MaxNewSize=5242880 -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=10485760
 * -XX:SurvivorRatio=8 -XX:PretenureSizeThreshold=10485760 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC
 * -XX:+PrintGCDetails
 * -XX:+PrintGCTimeStamps
 * -Xloggc:gc.log
 * 新生代大小 5M --> Eden区 只有 4M
 */
public class YoungGCDemo {
    public static void main(String[] args) {
        //三个 1Mb 数组
        byte[] arr = new byte[1024 * 1024];
        arr = new byte[1024 * 1024];
        arr = new byte[1024 * 1024];
        arr = null;
        //Eden区此时放不下，会触发 Young GC
        byte[] arr2 = new byte[2 * 1024 * 1024];

    }
    /** GC 日志如下：
     * Java HotSpot(TM) 64-Bit Server VM (25.221-b11) for windows-amd64 JRE (1.8.0_221-b11),
     * built on Jul  4 2019 04:39:29 by "java_re" with MS VC++ 10.0 (VS2010)
     * Memory: 4k page, physical 8244128k(2109240k free), swap 12678240k(2147228k free)
     * CommandLine flags: -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=10485760 -XX:MaxNewSize=5242880 -XX:NewSize=5242880
     * -XX:OldPLABSize=16 -XX:PretenureSizeThreshold=10485760 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=8
     * -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:-UseLargePagesIndividualAllocation -XX:+UseParNewGC
     *
     * 0.406: [GC (Allocation Failure) {GC原因} 0.407: [ParNew: 3825K->512K(4608K){存活对象变成 512K}, 0.0056737 secs]
     * 3825K->1707K(9728K){整个heap情况}, 0.0067867 secs]
     * [Times: user=0.03 sys=0.02, real=0.01 secs]
     *
     * {JVM退出时，当前堆的使用情况}
     * Heap
     *  {新生代情况}
     *  par new generation   total 4608K, used 3703K [0x00000000ff600000, 0x00000000ffb00000, 0x00000000ffb00000)
     *   eden space 4096K,  77% used [0x00000000ff600000, 0x00000000ff91dd08, 0x00000000ffa00000)
     *   from space 512K, 100% used [0x00000000ffa80000, 0x00000000ffb00000, 0x00000000ffb00000)
     *   to   space 512K,   0% used [0x00000000ffa00000, 0x00000000ffa00000, 0x00000000ffa80000)
     *   {老年代情况}
     *  concurrent mark-sweep generation total 5120K, used 1195K [0x00000000ffb00000, 0x0000000100000000, 0x0000000100000000)
     *  Metaspace       used 3224K, capacity 4496K, committed 4864K, reserved 1056768K
     *   class space    used 350K, capacity 388K, committed 512K, reserved 1048576K
     */
}
